console.log("=============全局参量，Value Properties========")
console.log(Infinity);
console.log(Infinity+1);
console.log(1/Infinity);

console.log(NaN === NaN);
console.log(Number.NaN == NaN);
console.log(isNaN(NaN));
console.log(isNaN(Number.NaN));

var x;
if(x === undefined){
    console.log("x is undefined");
}
else{
    console.log("x is not undefined");
}

console.log(typeof(null));
console.log(typeof(undefined));

console.log("=============全局参量，Function Properties========")
console.log(eval("0x3456"));
console.log(eval(new String("2+3")));
console.log(eval("3.45"));
var x = 4;
var y = 6;
console.log(eval("x+y"));

console.log(isFinite(Infinity));
console.log(isFinite(NaN));
console.log(isFinite(null));

console.log(parseFloat("345.456"));
console.log(parseFloat("314e-2"));
console.log(parseFloat("314e+2"));
console.log(parseFloat("314emoredata"));
console.log(parseFloat("FFF3")); // 返回NaN

console.log(parseInt("12345"));
console.log(parseInt("10101", 2));
console.log(parseInt("12345", 8));
console.log(parseInt("12345", 16));
console.log(parseInt("0x12345"));

console.log("=============全局参量，Fundamental objects========")
var o  = new Object();
console.log(typeof(o));
o = new Object(undefined);
console.log(typeof(o));
o = new Object(null);
console.log(typeof(o));
o = new Object(true)
console.log(typeof(o));

// 使用函数的构造函数创建函数对象
var addr = new Function('a','b', 'return a+b');
console.log(addr.name);
console.log(addr.length);
console.log(addr.prototype.toString());

/*
Difference between Function constructor and function declaration
Functions created with the Function constructor do not create closures 
to their creation contexts; they always are created in the global scope. 
When running them, they will only be able to access their own local 
variables and global ones, not the ones from the scope in which the 
Function constructor was called. This is different from using eval with 
code for a function expression.
*/
x = 10;
function createFunction1(){
    var x = 20;
    return new Function('return x'); // ref to global x
}
function createFunction2(){
    var x = 20;
    function f(){
        return x; // ref to local x
    }
    return f;
}
var f1 = createFunction1();
console.log(f1());  // 10
var f2 = createFunction2();
console.log(f2());  // 20

x = new Boolean(false);
console.log(x);     // false
x = new Boolean(null);
console.log(x);     // false
x = new Boolean(NaN);
console.log(x);     // false
x = new Boolean(undefined);
console.log(x);     // false
x = new Boolean('');
console.log(x);     // false
x = new Boolean(0);
console.log(x);     // false
x = new Boolean(10);
console.log(x);     // true
x = new Boolean(true);
console.log(x);     // true
x = new Boolean('0');
console.log(x);     // true

// Every symbol value returned from Symbol() is unique.  
// A symbol value may be used as an identifier for object properties; 
// Symbole不支持new操作符
var sym1 = Symbol();
console.log(sym1);
var sym2 = Symbol("foo");
console.log(sym2);
console.log(Symbol("f") === Symbol("f"));   // false


try{
    throw new Error("Whoops error!");
}catch(e){
    console.log(e.name+": "+e.message);
}

try{
    sym1();
}catch(e){
    if(e instanceof EvalError){
    console.log(e.name+": "+e.message);
    }else if(e instanceof EvalError){
    console.log(e.name+": "+e.message);
    }else if(e instanceof InternalError){
    console.log(e.name+": "+e.message);
    }else if(e instanceof RangeError){
    console.log(e.name+": "+e.message);    
    }else if(e instanceof TypeError){
    console.log(e.name+": "+e.message);   
    }else{
    console.log(e.name+": "+e.message);        
    }
}
console.log("=============全局参量，Numbers and Dates========")

console.log(Number.EPSILON);
console.log(Number.isNaN(45));
console.log(Number("123"));
console.log(Number("0x234"));


console.log(Math.E);
console.log(Math.LN10);
console.log(Math.PI);
console.log(Math.SQRT2);
console.log(Math.abs(-5));
console.log(Math.sin(-5));
console.log(Math.random());
console.log(Math.random());
console.log(Math.round(40));

var today = new Date();
console.log(today);
console.log(today.getDate());

console.log("=============全局参量，Text Processing========")
var str = `Hello`;
console.log(`${str} zhadaolong`);
console.log(str.charAt(1));
console.log(str[1]);
var str_obj = new String(str);
console.log(typeof str);
console.log(typeof str_obj);
str_obj = "name is zha";
console.log(typeof(str_obj));   // 赋值后就变成string类型了
console.log(str_obj.substr(0,2)); // na
console.log(str_obj.substring(2,4));    // me

var myReg = new RegExp("/^a..A$/");
var re = /(.)S(.)/;
var str = "John Smith";
console.log(str.replace(re, "1"));
str = "Please yes \n make my day!";
console.log(str.match(/yes.*day/));


console.log("=============全局参量，Indexed Collections========")
var fruits = ["Applet", "Banana"];
console.log(typeof(fruits));
console.log(fruits);
console.log(fruits.length);
var myArray = new Array(fruits);
console.log(typeof(myArray));
console.log(myArray);

var iArray = new Int8Array(10);
var iArray = new Uint8Array(10);
var iArray = new Int16Array(10);
var iArray = new Int32Array(10);

console.log("=============全局参量，Keyed Collections========")
var myMap = new Map();
myMap.set(1,"123");
myMap.set(2,355);
myMap.set(3,true);
console.log(myMap.get(1));
console.log(myMap.get(2));
console.log(myMap.get(3));
myMap.forEach(function(val,key){
    console.log(key+" : "+val);
})

var mySet = new Set();
mySet.add("123");
mySet.add(123);
mySet.add([1,2,3]);
mySet.add({1:"23",2:"34"});
for(let item of mySet){
    console.log(item);
}
mySet.forEach(function(val){
    console.log(val);
    
})
// 浏览器暂不支持
//var mywMap = new WeekMap();
//var mywSet = new WeekSet();

console.log("=============全局参量，Vector Collections========")
console.log("SIMD")
console.log("SIMD.Float32x4")

console.log("=============全局参量，Structured Data========")
var myArray = new ArrayBuffer(10);
var dv = new DataView(myArray, 0);
for (let i=0; i<10; i++){
    console.log(dv.getUint8(i));
}
dv.setInt8(0,22);
console.log(dv.getUint8(0));

console.log("JSON: JavaScript Object Notation")


console.log("=============全局参量，Control Abstraction Objects========")

var myFirstPromise = new Promise(function(resolve, reject){
    setTimeout(function(){
        resolve("Success!");
    }, 3000);
})
myFirstPromise.then(function(ret){
    console.log("myFirstPromise "+ret);
})

function* idMaker(){
    var index = 0;
    while(index < 10){
        yield index++;
    }
}
var gen = idMaker();
//for(let i of gen){
//    console.log(i);
//}
console.log(gen.next().value); // 调用了上面，next就不是从0开始了
console.log(gen.next().value);
console.log(gen.next().value);

console.log("=============全局参量，Reflect========")
console.log("Reflect");
console.log("Proxy");
console.log("set");
console.log("get");






